<?php
class DateCategoriesController extends AppController {
	
	var $name = 'DateCategories' ;
	var $helpers = array ( 'Html' , 'Form', 'context'  ) ;
	var $components = array ( 'context' , 'RequestHandler' ) ;
	
	function index () {
		$this->DateCategory->recursive = 0 ;
		$this->set ( 'dateCategories', $this->DateCategory->findAll () ) ;
	}
	
	function view ( $id = null ) {
		if (! $id) {
			$this->Session->setFlash ( 'Invalid id for Date Category.' ) ;
			$this->redirect ( '/date_categories/index' ) ;
		}
		$this->set ( 'dateCategory', $this->DateCategory->read ( null, $id ) ) ;
	}
	
	function add () {
		
		if (empty ( $this->data )) {
			$this->render () ;
		} else {
			$this->cleanUpFields () ;
			if ($this->DateCategory->save ( $this->data )) {
				$this->Session->setFlash ( 'The Date Category has been saved' ) ;
				$this->redirect ( '/date_categories/index' ) ;
			} else {
				$this->Session->setFlash ( 'Please correct errors below.' ) ;
			}
		}
	}
	
	function edit ( $id = null ) {
		if (empty ( $this->data )) {
			if (! $id) {
				$this->Session->setFlash ( 'Invalid id for Date Category' ) ;
				$this->redirect ( '/date_categories/index' ) ;
			}
			$this->data = $this->DateCategory->read ( null, $id ) ;
		} else {
			$this->cleanUpFields () ;
			if ($this->DateCategory->save ( $this->data )) {
				$this->Session->setFlash ( 'The DateCategory has been saved' ) ;
				$this->redirect ( '/date_categories/index' ) ;
			} else {
				$this->Session->setFlash ( 'Please correct errors below.' ) ;
			}
		}
	}
	
	function delete ( $id = null ) {
		if (! $id) {
			$this->Session->setFlash ( 'Invalid id for Date Category' ) ;
			$this->redirect ( '/date_categories/index' ) ;
		}
		if ($this->DateCategory->del ( $id )) {
			$this->Session->setFlash ( 'The Date Category deleted: id ' . $id . '' ) ;
			$this->redirect ( '/date_categories/index' ) ;
		}
	}
	
	function admin_index () {
		$this->context->method = 'index' ;
		$this->context->checkSession ( $this ) ;
		$this->layout = "admin" ;
		
		$this->DateCategory->recursive = 0 ;
		$this->set ( 'dateCategories', $this->DateCategory->findAll () ) ;
	}
	
	function admin_view ( $id = null ) {
		if (! $id) {
			$this->Session->setFlash ( 'Invalid id for Date Category.' ) ;
			$this->redirect ( '/admin/date_categories/index' ) ;
		}
		$this->set ( 'dateCategory', $this->DateCategory->read ( null, $id ) ) ;
	}
	
	function admin_add () {
		$this->context->checkSession ( $this ) ;
		$this->context->method = 'add' ;
		$this->layout = "admin" ;
		
		if (empty ( $this->data )) {
			$this->render () ;
		} else {
			$this->cleanUpFields () ;
			if ($this->DateCategory->save ( $this->data )) {
				$this->Session->setFlash ( 'The Date Category has been saved' ) ;
				$this->redirect ( '/admin/date_categories/index' ) ;
			} else {
				$this->Session->setFlash ( 'Please correct errors below.' ) ;
			}
		}
	}
	
	function admin_edit ( $id = null ) {
		$this->context->checkSession ( $this ) ;
		$this->context->method = 'add' ;
		$this->layout = "admin" ;
		
		if (empty ( $this->data )) {
			if (! $id) {
				$this->Session->setFlash ( 'Invalid id for Date Category' ) ;
				$this->redirect ( '/admin/date_categories/index' ) ;
			}
			$this->DateCategory->category_id = $id ;
			$this->data = $this->DateCategory->read () ;
		} else {
			$this->cleanUpFields () ;
			if ($this->DateCategory->save ( $this->data )) {
				$this->Session->setFlash ( 'The DateCategory has been saved' ) ;
				$this->redirect ( '/admin/date_categories/index' ) ;
			} else {
				$this->Session->setFlash ( 'Please correct errors below.' ) ;
			}
		}
	}
	
	function admin_delete ( $id = null ) {
		$this->context->checkSession ( $this ) ;
		$this->layout = "admin" ;
		
		if (empty ( $this->data )) {
			$this->DateCategory->id = $id ;
			$this->data = $this->DateCategory->read () ;
			$this->set ( 'DateCategory', $this->DateCategory->read () ) ;
		} else {
			
			$this->DateCategory->del ( $this->data [ 'DateCategory' ] [ 'category_id' ] ) ;
			$this->redirect ( '/admin/date_categories/' ) ;
		}
		
		if (! $id) {
			$this->Session->setFlash ( 'Invalid id for Date Category' ) ;
			$this->redirect ( '/admin/date_categories/index' ) ;
		}
		if ($this->DateCategory->del ( $id )) {
			$this->Session->setFlash ( 'The Date Category deleted: id ' . $id . '' ) ;
			$this->redirect ( '/admin/date_categories/index' ) ;
		}
	}

}
?>